<?php include "./pc/view/header.inc.htm"; ?>

<div class="container">
    <div class="addtopic">
        <form method="POST" id="post_create_form" action="post-create-<?php echo $tid; ?>.htm">
        <div class="content-header">
            <div class="tw-header-inner">回帖</div>
        </div>
        <div class="content-post">
            <div class="post-inner">
                <textarea class="input-body" id="post_message" name="message" placeholder="内容" style="width: 93%; height: 200px;"></textarea>
                <div class="post-button-right mt15">
                    <button class="Button Button--primary" type="button" loading-text="正在提交...">
                        <span class="submit-button-text">
                            发表
                        </span>
                    </button>
                </div>
                <!-- <div class="post-button-right mt15"></div> -->
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>

<?php include "./pc/view/footer.inc.htm"; ?>

<link rel="stylesheet" type="text/css" href="xneditor/editor.css" />

<script src="xiunoui/async.js"></script>
<script src="xiunoui/upload.js"></script>
<script src="xneditor/editor.js"></script>
<script>

//setInterval(function() {

var editor = new $.XNEditor({textarea: 'post_message', image_upload_url:'post-upload-1.htm', image_upload_width: (<?php echo $conf['upload_image_width']; ?> - 40), file_upload_url:'post-upload-0.htm'});

var jform = $('#post_create_form');
var jinput = jform.find('input');
var jmessage = $('#post_message');
var jsubmit = jform.find('button').filter('[type="button"]');

var tid = <?php echo $tid; ?>;

jsubmit.off('click').on('click', function() {
	
	if(!jmessage.val()) {
		editor.jeditor.popover('请输入内容');
		editor.focus();
		return false;
	}
	
	jsubmit.button('loading');
	var postdata = jform.serializeObj();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.button('回帖成功');
			setTimeout(function() {editor.clear(); window.location='thread-'+tid+'.htm';}, 1000);
			return;
		} else if(code == 2) {
			jmessage.popover(message).focus();
		} else {
			$.alert(message);
		} 
		jsubmit.button('reset');
	});
	return false;
});
//}, 1000);
</script>